package com.zhuiyun.project.api.appuserreport.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.zhuiyun.project.api.appuser.service.AppUserService;
import com.zhuiyun.project.api.appuserreport.entity.UserReport;
import com.zhuiyun.project.api.appuserreport.mapper.AppUserReportMapper;
import com.zhuiyun.project.api.appuserreport.model.AppUerReportModel;
import com.zhuiyun.project.api.appuserreport.service.AppUserReportService;
import com.zhuiyun.project.api.check.entity.Check;
import com.zhuiyun.project.api.check.model.CheckModel;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.BeanUtils;
import com.zhuiyun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author hbx
 * @Date 2023/6/5 17:11
 **/
@Service
public class AppUserReportServiceImpl implements AppUserReportService {

    @Autowired
    AppUserReportMapper appUserReportMapper;

    @Autowired
    AppUserService appUserService;

    /**
     * @param appUerReportModel
     * @param pageRequest
     * @Author 韩佳轩
     * @Description 举报用户
     * @Date 2023/8/8 16:20
     * @Return com.zhuiyun.project.util.pageUtil.PageResult
     */

    @Override
    public PageResult getUserReportsBy(AppUerReportModel appUerReportModel, PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        List<AppUerReportModel> userReportsBy = appUserReportMapper.getUserReportsBy(appUerReportModel);
        return MybatisPageHelper.getPageResult(userReportsBy);
    }

    /**
     * @param userReport 1是警告 3是注销
     * @Author kdj
     * @Description 同意举报
     * @Date 2023/8/14 16:00
     * @Return int
     */
    @Override
    public int userReport(UserReport userReport) {
        int i = 0;
        //判断类型
        if (userReport.getProcessingResult() == 0) {
            //警告
            i = appUserReportMapper.userReport1(userReport.getId(), userReport.getProcessor());
            return i;
        } else if(userReport.getProcessingResult() == 1){
            //注销
            i = appUserReportMapper.userReport2(userReport.getId(), userReport.getProcessor());
            //修改用户类型
            appUserService.toProhibition(userReport.getReportedUserId());
            return i;
        }
        return i;
    }

    /**
     * @param userReport
     * @Author kdj
     * @Description 用户驳回同意申请
     * @Date 2023/8/14 15:38
     * @Return int
     */
    @Override
    public int userReportReject(UserReport userReport) {
        int i = appUserReportMapper.userReportReject(userReport);
        return i;
    }

    /**
     * @Author kdj
     * @Description 查询  举报人记录
     * @Date 2023/8/14 15:48
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @Override
    public CommonResult userReportList() {
        List<UserReport> userReport = appUserReportMapper.userReportList();
        return CommonResult.ok(userReport);
    }

    /**
     * @param userReport
     * @Author kdj
     * @Description 添加审核记录
     * @Date 2023/8/14 15:47
     * @Return int
     */
    @Override
    public int userReportsy(UserReport userReport) {
        Date date = new Date();
        userReport.setCreateTime(date);
        userReport.setUpdateTime(date);
        userReport.setReportTime(date);
        userReport.setReportStatus(2);
        userReport.setDelFlag(0);
        return appUserReportMapper.userReportsy(userReport);
    }


}